//
//  StringUtils.m
//  MiniWeChat
//
//  Created by ByteDance on 2025/6/30.
//


#import "StrUtil.h"

@implementation StrUtil

+ (NSString *)concatenateString:(NSString *)stringA withString:(NSString *)stringB {
    // 处理 nil 值
    if (!stringA) stringA = @"";
    if (!stringB) stringB = @"";
    
    // 使用 stringByAppendingFormat 拼接字符串
    return [NSString stringWithFormat:@"%@&%@", stringA, stringB];
}

+ (NSArray<NSString *> *)splitConcatenatedString:(NSString *)concatenatedString {
    // 处理 nil 或空字符串
    if (!concatenatedString || concatenatedString.length == 0) {
        return @[@"", @""];
    }
    
    // 使用 componentsSeparatedByString 方法拆分字符串
    NSArray<NSString *> *components = [concatenatedString componentsSeparatedByString:@"&"];
    
    // 确保结果数组包含两个元素
    if (components.count >= 2) {
        return @[components[0], components[1]];
    } else if (components.count == 1) {
        return @[components[0], @""];
    } else {
        return @[@"", @""];
    }
}

@end
